import sqlite3 as sql
import time
import pandas as pd


def classes(hours):
    if 8 <= hours <= 9 + 40 / 60:
        return '1-2'
    elif 10 <= hours <= 11 + 40 / 60:
        return '3-4'
    elif 14 <= hours <= 15 + 40 / 60:
        return '5-6'
    elif 16 <= hours <= 17 + 40 / 60:
        return '7-8'
    elif 19 <= hours <= 20 + 40 / 60:
        return '9-10'
    else:
        return None


def doubleWeek(week):
    if week % 2 == 0:
        return '双周'
    else:
        return '单周'


times = time.strftime('%Y-%m-%d-%W-%w-%H-%M-%S').split('-')
year = times[0]
month = times[1]
day = times[2]
week = int(times[3])
weekday = int(times[4])
hour = int(times[5])
minute = int(times[6])
hours = hour + minute / 60
class_what = classes(hours)
double_what = doubleWeek(week)

con = sql.connect('df_lesson_list.db')
query = con.execute(
    '''select 上课教师,课程名称,教室 from lessonlist
       where (%s >= 起周 and %s <= 止周)
       and (%s = 上课星期)
       and (起止节 like "%s")
       and (单双周 like "全部" or 单双周 like "%s")'''
    % (week, week, weekday, class_what, double_what))
print('当前时间:', year, '年', month, '月', day, '日，', hour, '时', minute, '分')
print('当前教历：第', week, '周 星期', weekday, '第', class_what, '节课')
print('当前正在上课的教师列表：')
class_list = []
for i in query:
    class_list.append(i)
con.close()
df_class = pd.DataFrame(class_list, columns=('上课教师', '课程名称', '上课教室'))
if not df_class.empty:
    print(df_class)
else:
    print('当前没有教师在上课！')
